package org.linlinjava.litemall.admin.web;

import org.linlinjava.litemall.admin.service.AdminGoodsService;
import org.linlinjava.litemall.admin.service.ISBNBookInfoService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/isbn")
public class ISBNBookInfoController {
    @Autowired
    private ISBNBookInfoService isbnBookInfoService;
    @Autowired
    private AdminGoodsService adminGoodsService;

    public static final String KEY = "f541ed07e4aeee5dd1c9d14664b6df0e";

    @GetMapping("/info")
    public Object getInfo(@RequestParam String sub) {
        Object o = adminGoodsService.queryByIsbn(sub);
        if (o != null) {
            return ResponseUtil.fail(400, "该书已在库存", o);
        }
        return ResponseUtil.ok(isbnBookInfoService.getBookInfo(KEY,sub));
    }
}
